package com.myacg.editor.common.utils;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.myacg.editor.common.unit.panel.base.ShadowPanel;

/**
 * 渐变色填充工具
 * @author Administrator
 *
 */
public class GradualChangeUtils {
	 /**
	  * //水晶石效果  
	  * //出现光感效果的原理是上半部  
	  * @param colorLength 宽/或高的长度
	  * @param colorPrefix 前半部分的颜色基数
	  * @param n  后半部分的变化系数
	  * @return
	  */
	  public static int[][] getCrystalColors(int colorLength,int colorPrefix , double n) {  
	      int[][] delColor = new int[colorLength][3]; //  
	      int li_half = colorLength / 2; //一半!  
	      if (li_half == 0) {  
	          li_half = 1;  
	      }  
	      int li_d1 = 100 / li_half; //如果是10,则递减10,如果是100,则递减1  
	      if (li_d1 == 0) {  
	          li_d1 = 1;  
	      }  
	      //上半部分
	      int li_prefix = colorPrefix; //有个前辍,可以随便设个值,就看你想渐变得白的还是黑的!  
	      for (int i = li_half - 1; i >= 0; i--) { //  
	          delColor[i][0] = li_prefix + (li_half - 1 - i) * li_d1;  
	          delColor[i][1] = li_prefix + (li_half - 1 - i) * li_d1;  
	          delColor[i][2] = li_prefix + (li_half - 1 - i) * li_d1;  
	      }  
	      //下半部分
	      int li_d2 = (int) ((100 / li_half) * n); //关键这里有个系数变化,才会出现光感，水波等效果  
	      if (li_d2 == 0) {  
	          li_d2 = 1;  
	      }  
	      for (int i = li_half; i < colorLength; i++) {  
	          delColor[i][0] = (i - li_half) * li_d2; //  
	          delColor[i][1] = (i - li_half) * li_d2; //  
	          delColor[i][2] = (i - li_half) * li_d2; //  
	      }  
	      return delColor;  
	  } 
	  
	  /**
	   * 渐变效果
	   * @param colorLength
	   * @param colorPrefix
	   * @return
	   */
	  public static int[][] getChengeColors(int colorLength,int colorPrefix,boolean isUper) {  
	      int[][] delColor = new int[colorLength][3]; //  
	      int li_d1 = 100 / colorLength; //如果是10,则递减10,如果是100,则递减1  
	      if (li_d1 == 0) {  
	          li_d1 = 1;  
	      }  
	      //上半部分
	      int li_prefix = colorPrefix; //有个前辍,可以随便设个值,就看你想渐变得白的还是黑的!  
	      if(isUper){
	    	  for (int i = colorLength - 1; i >= 0; i--) { //  
		          delColor[i][0] = li_prefix + (colorLength - 1 - i) * li_d1;  
		          delColor[i][1] = li_prefix + (colorLength - 1 - i) * li_d1;  
		          delColor[i][2] = li_prefix + (colorLength - 1 - i) * li_d1;  
		      }  
	      }else{
	    	  for (int i = 0; i <= colorLength - 1; i++) { //  
		          delColor[i][0] = li_prefix + (i) * li_d1;  
		          delColor[i][1] = li_prefix + (i) * li_d1;  
		          delColor[i][2] = li_prefix + (i) * li_d1;  
		      } 
	      }
	       
	      return delColor;  
	  }  
	  
	  /**
	   * 将颜色数组从上到下填充到某个区域
	   * @param g2
	   * @param baseColor
	   * @param li_delcolors
	   * @param width
	   */
	  public static void   drawColorsToPaenlUpStart(Graphics g2,Color baseColor,int[][] li_delcolors ,int width){
		  drawColorsToPaenl(g2, baseColor, li_delcolors, width, true);
	  }
	  /**
	   * 将颜色数组从左到右填充到某个区域
	   * @param g2
	   * @param baseColor
	   * @param li_delcolors
	   * @param height
	   */
	  public static void   drawColorsToPaenlLeftStart(Graphics g2,Color baseColor,int[][] li_delcolors ,int height){
		  drawColorsToPaenl(g2, baseColor, li_delcolors, height, false);
	  }
	  public static void  drawColorsToPaenl(Graphics g2,Color baseColor,int[][] li_delcolors ,int drawLength, boolean isUpStart){
		  for (int i = 0; i < li_delcolors.length; i++) {  //循环画出每一帧！！  
	          int li_r =  baseColor.getRed()   + li_delcolors[i][0]; //R  
	          int li_g =  baseColor.getGreen() + li_delcolors[i][1]; //G  
	          int li_b =  baseColor.getBlue()  + li_delcolors[i][2]; //B  
	          //如果溢出255,则当255,否则报错!  
	          if (li_r > 255) {  
	              li_r = 255;  
	          }  
	          if (li_g > 255) {  
	              li_g = 255;  
	          }  
	          if (li_b > 255) {  
	              li_b = 255;  
	          }  
	          g2.setColor(new Color(li_r, li_g, li_b)); //设置颜色!!  
	          if(isUpStart){
	        	  g2.fillRect(0 + 1, i + 1,drawLength, 1); //从上到下填充
	          }else{
	        	  g2.fillRect(i + 1, 0 + 1, 1, drawLength); //从左到右填充
	          }
	      }  
	  }	
	  
	  
	   
	  
	 
}
